/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mx.its.talleres.Bl;

import java.util.List;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import mx.its.talleres.Dao.TallerDaoLocal;
import mx.its.talleres.Enumeracion.EstadoTransaccion;
import mx.its.talleres.modelo.Taller;

/**
 *
 * @author Yessy
 */
@Stateless
public class TallerBl implements TallerBlLocal {

    @EJB
    private TallerDaoLocal tallerDao;

    @Override
    public EstadoTransaccion registrar(Taller taller) {
        if (tallerDao.findDuplicity(taller)) {
            return EstadoTransaccion.INCOMPLETO;

        } else {
            tallerDao.create(taller);
            return EstadoTransaccion.COMPLETO;

        }
    }

    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")
    @Override
    public EstadoTransaccion editar(Taller taller) {
        if (taller.getId() == null || tallerDao.find(taller.getId()) == null) {
            return EstadoTransaccion.INCOMPLETO;
        } else {
            tallerDao.edit(taller);
            return EstadoTransaccion.COMPLETO;
        }
    }

    @Override
    public EstadoTransaccion eliminar(Taller taller) {
     if (taller.getId() == null || tallerDao.find(taller.getId()) == null) {
            return EstadoTransaccion.INCOMPLETO;
        } else {
            tallerDao.remove(taller);
            return EstadoTransaccion.COMPLETO;

        }
    }

    @Override
    public List<Taller> getAll() {
          return tallerDao.findAll();
    }
    
}
